using System;
using System.Collections.Generic;
using System.Text;
using Meebey.SmartIrc4net;
using System.Windows.Forms;
using System.Collections;

namespace dotIRC
{
    public class IrcSession : IrcClient
    {
        StatusForm _ownerForm;
        DebugForm _debugForm;
        Hashtable _chatWindows = new Hashtable();  // key:string, value:ChatForm

        public IrcSession() : base()
        {
            OnConnected += new EventHandler(_onConnected);
            OnJoin += new JoinEventHandler(_onJoin);
        }

        public IrcSession(StatusForm owner) : this()
        {
            _ownerForm = owner;
        }

        void _onConnected(object sender, EventArgs e)
        {
//#if DEBUG
            if (_debugForm == null)
                _debugForm = new DebugForm(this);
            _debugForm.Show();
//#endif
        }

        void _onJoin(object sender, JoinEventArgs e)
        {
            if (IsMe(e.Who) && !_chatWindows.Contains(e.Channel))
            {
                if (_ownerForm.InvokeRequired)   // Tie the new window to the right thread...
                    _ownerForm.BeginInvoke(new JoinEventHandler(_onJoin), new object[] { sender, e });
                else
                {
                    new ChannelForm(this, e.Channel).Show();
                }
            }
        }

        public StatusForm Owner
        {
            get
            {
                return _ownerForm;
            }
        }
        public Hashtable ChatWindows
        {
            get
            {
                return _chatWindows;
            }
        }

        /*
        public override void Disconnect()
        {
            OnDisconnected(this, new DisconnectedEventArgs(true));
            base.Disconnect();
        }
    }

    public class DisconnectedEventArgs : EventArgs
    {
        bool _requested;

        public bool Requested
        {
            get
            {
                return _requested;
            }
        }

        internal DisconnectedEventArgs(bool requested)
        {
            _requested = requested;
        }*/
    }
}
